package com.huawei.hms.auth.api.signin.internal;

import android.text.TextUtils;
import com.huawei.hms.auth.api.signin.HuaweiIdSignInResult;
import com.huawei.hms.auth.api.signin.internal.a.b;
import com.huawei.hms.auth.api.signin.internal.b.a;
import com.huawei.hms.common.ApiException;
import com.huawei.hms.common.internal.AnyClient;
import com.huawei.hms.common.internal.ResponseErrorCode;
import com.huawei.hms.common.internal.TaskApiCall;
import com.huawei.hms.support.api.client.Status;
import com.huawei.hms.support.api.entity.hwid.HwIDNaming;
import com.huawei.hms.support.api.hwid.SignInHuaweiId;
import com.huawei.hms.support.hianalytics.HiAnalyticsClient;
import com.huawei.hms.support.log.HMSLog;
import o.fjx;
import org.json.JSONException;

public class f extends TaskApiCall<b, SignInHuaweiId> {
    public /* synthetic */ void doExecute(AnyClient anyClient, ResponseErrorCode responseErrorCode, String str, fjx o_fjx) {
        a((b) anyClient, responseErrorCode, str, o_fjx);
    }

    public f(String str, String str2, String str3) {
        super(str, str2, str3);
    }

    protected void a(b bVar, ResponseErrorCode responseErrorCode, String str, fjx<SignInHuaweiId> o_fjx_com_huawei_hms_support_api_hwid_SignInHuaweiId) {
        SignInHuaweiId signInHuaweiId;
        HMSLog.i("[HUAWEIIDSDK]SignInTaskApiCall", "ResponseErrorCode.status:" + String.valueOf(responseErrorCode.getErrorCode()));
        int errorCode = responseErrorCode.getErrorCode();
        if (TextUtils.isEmpty(str)) {
            HMSLog.i("[HUAWEIIDSDK]SignInTaskApiCall", "signIn complete, response is null, failed");
            o_fjx_com_huawei_hms_support_api_hwid_SignInHuaweiId.ॱ(new ApiException(new Status(responseErrorCode.getErrorCode(), responseErrorCode.getErrorReason())));
            signInHuaweiId = null;
        } else {
            try {
                HuaweiIdSignInResult fromJson = new HuaweiIdSignInResult().fromJson(str);
                errorCode = fromJson.getStatus().getStatusCode();
                if (fromJson.isSuccess()) {
                    HMSLog.i("[HUAWEIIDSDK]SignInTaskApiCall", "signIn success");
                    new b(bVar.getContext()).a();
                    signInHuaweiId = fromJson.getSignInAccount();
                    try {
                        o_fjx_com_huawei_hms_support_api_hwid_SignInHuaweiId.ॱ(fromJson.getSignInAccount());
                    } catch (JSONException e) {
                        HMSLog.w("[HUAWEIIDSDK]SignInTaskApiCall", "signIn complete, but parser json exception");
                        o_fjx_com_huawei_hms_support_api_hwid_SignInHuaweiId.ॱ(new ApiException(new Status(responseErrorCode.getErrorCode(), responseErrorCode.getErrorReason())));
                        a.a().a(signInHuaweiId, null);
                        HiAnalyticsClient.reportExit(bVar.getContext(), HwIDNaming.silentSignIn, getTransactionId(), com.huawei.hms.auth.api.signin.internal.c.b.a(errorCode), errorCode, com.huawei.hms.auth.api.signin.internal.c.a.a());
                    }
                }
                HMSLog.i("[HUAWEIIDSDK]SignInTaskApiCall", "signIn failed");
                o_fjx_com_huawei_hms_support_api_hwid_SignInHuaweiId.ॱ(new ApiException(fromJson.getStatus()));
                signInHuaweiId = null;
            } catch (JSONException e2) {
                signInHuaweiId = null;
                HMSLog.w("[HUAWEIIDSDK]SignInTaskApiCall", "signIn complete, but parser json exception");
                o_fjx_com_huawei_hms_support_api_hwid_SignInHuaweiId.ॱ(new ApiException(new Status(responseErrorCode.getErrorCode(), responseErrorCode.getErrorReason())));
                a.a().a(signInHuaweiId, null);
                HiAnalyticsClient.reportExit(bVar.getContext(), HwIDNaming.silentSignIn, getTransactionId(), com.huawei.hms.auth.api.signin.internal.c.b.a(errorCode), errorCode, com.huawei.hms.auth.api.signin.internal.c.a.a());
            }
        }
        a.a().a(signInHuaweiId, null);
        HiAnalyticsClient.reportExit(bVar.getContext(), HwIDNaming.silentSignIn, getTransactionId(), com.huawei.hms.auth.api.signin.internal.c.b.a(errorCode), errorCode, com.huawei.hms.auth.api.signin.internal.c.a.a());
    }
}
